/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package italk.ui.vidw.panel;

import italk.client.bean.State.ContactState;
import italk.ui.action.ActionManager;
import italk.ui.action.LoginAction;
import italk.ui.bean.ComboBoxImageItem;
import italk.ui.renderer.IconListRenderer;
import italk.util.ImageManager;
import italk.util.LanguageLoader;

import java.awt.Dimension;
import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 
 * @author chenzhihui
 */
public class LoginPanel extends javax.swing.JPanel {

	private static final long serialVersionUID = -1026483093399411628L;

	/**
	 * Creates new form LoginPanel
	 */
	public LoginPanel() {
		initComponents();
		init();
		initAction();
		this.setVisible(true);
	}

	/**
	 * This method is called from within the constructor to initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is always
	 * regenerated by the Form Editor.
	 */
	@SuppressWarnings("unchecked")
	// <editor-fold defaultstate="collapsed"
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        topPanel = new javax.swing.JPanel();
        lblBanner = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        comboAccount = new javax.swing.JComboBox();
        jLabel3 = new javax.swing.JLabel();
        textPassword = new javax.swing.JPasswordField();
        btnLogin = new javax.swing.JButton();
        comboStatus = new javax.swing.JComboBox();
        toolBarLogin = new javax.swing.JToolBar();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();

        setPreferredSize(new java.awt.Dimension(255, 555));

        topPanel.setPreferredSize(new java.awt.Dimension(255, 150));
        topPanel.setLayout(new java.awt.BorderLayout());

        lblBanner.setPreferredSize(new java.awt.Dimension(255, 150));
        topPanel.add(lblBanner, java.awt.BorderLayout.CENTER);

        jLabel2.setText(LanguageLoader.getString("account"));

        comboAccount.setEditable(true);
        comboAccount.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "444674479", "6208317", "917362009" }));

        jLabel3.setText(LanguageLoader.getString("password"));

        btnLogin.setText(LanguageLoader.getString("login"));

        comboStatus.setPreferredSize(new java.awt.Dimension(40, 28));

        toolBarLogin.setFloatable(false);
        toolBarLogin.setRollover(true);

        jButton1.setText("Page");
        jButton1.setActionCommand("Download");
        jButton1.setFocusable(false);
        jButton1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton1.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        toolBarLogin.add(jButton1);

        jButton2.setText("Above");
        jButton2.setFocusable(false);
        jButton2.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton2.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        toolBarLogin.add(jButton2);

        jButton3.setText("Icon");
        jButton3.setFocusable(false);
        jButton3.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton3.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        toolBarLogin.add(jButton3);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(topPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addGap(27, 27, 27)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(toolBarLogin, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGap(46, 46, 46))
                    .addComponent(comboAccount, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(textPassword)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(btnLogin, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(comboStatus, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel3)
                            .addComponent(jLabel2))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addGap(32, 32, 32))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(topPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(comboAccount, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(textPassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(comboStatus, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnLogin))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 160, Short.MAX_VALUE)
                .addComponent(toolBarLogin, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(38, 38, 38))
        );
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnLogin;
    private javax.swing.JComboBox comboAccount;
    private javax.swing.JComboBox comboStatus;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel lblBanner;
    private javax.swing.JPasswordField textPassword;
    private javax.swing.JToolBar toolBarLogin;
    private javax.swing.JPanel topPanel;
    // End of variables declaration//GEN-END:variables

	public void init() {
		// 设置Banner图片
		this.lblBanner.setIcon(ImageManager.getImageIconByShortName("icons"
				+ File.separator + "banner-raster.jpg"));

		// 设置登录状态
		List<ContactState> status = ContactState.getBuddyList();
		ComboBoxImageItem statusItem = null;
		this.comboStatus.setRenderer(new IconListRenderer());
		String extension = ".png";
		String iconDir = "status" + File.separator;
		for (ContactState state : status) {
			statusItem = new ComboBoxImageItem(state.toString(), iconDir
					+ ContactState.toLowerCase(state) + extension);
			comboStatus.addItem(statusItem);
		}
		comboStatus.setPreferredSize(new Dimension(40, 28));
	}
	
	public void initAction() {
		LoginAction loginAction = (LoginAction) ActionManager
				.getAction(LoginAction.class);
		Map<String, String> data = new HashMap<String, String>();
		data.put("account", this.comboAccount.getSelectedItem().toString());
		data.put("password", this.textPassword.getPassword().toString());
		loginAction.setData(data);
		this.btnLogin.setAction(loginAction);
	}
}